package io.polly.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RedisConnectionAspect {

    private static final Logger logger = LoggerFactory.getLogger(RedisConnectionAspect.class);

    @Around("@annotation(io.polly.annotation.RedisConnectExceptionCompatible) " +
            "|| @within(io.polly.annotation.RedisConnectExceptionCompatible)")
    public Object handleConnectionException(ProceedingJoinPoint point) throws Throwable {
        try{
            return point.proceed();
        }catch(RedisConnectionFailureException e){
            logger.error("redis connection exception:",e);
            return null;
        }
    }
}
